package cn.t.web;

import cn.t.constants.ResponseError;
import cn.t.core.enums.EnumData;
import cn.t.core.exception.BizException;
import cn.t.core.mode.Result;
import cn.t.dto.api.ContactDTO;
import cn.t.dto.api.CustomerAddressVO;
import cn.t.facade.CommonFacade;
import cn.t.vo.UnitVO;
import cn.t.vo.order.RegionVO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

;

/**
 * 通用接口
 */
@Slf4j
@RequestMapping("/common")
@RestController
@AllArgsConstructor
public class CommonController {

    private final CommonFacade commonFacade;

    /**
     * 查询所有枚举字典内容
     */
    @PostMapping("/dic")
    public Map<String, List<EnumData>> getDicMap(@RequestBody(required = false) List<String> enumNames) {
        return commonFacade.getDicMap(enumNames);
    }

    /**
     * 查询省市区下拉框数据
     */
    @GetMapping("/region")
    public List<RegionVO> getRegion(@RequestParam(required = false) String parentCode) {
        return commonFacade.getRegion(parentCode);
    }

    /**
     * 上传文件，返回文件地址
     */
    @PostMapping("/upload")
    public Result<String> upload(@RequestParam MultipartFile file) {
        return Result.success(commonFacade.upload(file));
    }

    /**
     * 查询单位下拉框数据
     * @param type 1：chargeUnit（计价单位）2：physicalUnit（物理单位）
     */
    @GetMapping("/unit")
    public List<UnitVO> unit(@RequestParam(required = false) String type) {
        return commonFacade.getUnit(type);
    }


    @GetMapping("/test")
    public void unit() {
       throw new BizException(ResponseError.DATA_ERR, "测试异常");
    }

}

